package tung.niit.ict;

import java.util.ArrayList;

import tung.niit.ict.adapter.LendedBookAdapter;
import tung.niit.ict.model.LendedBook;
import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class Profile extends Activity {

	private ListView listLendedBook;
	private ArrayList<LendedBook> arrayLendedBook;
	private LendedBookAdapter adapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_profile);
		
		listLendedBook = (ListView)findViewById(R.id.listviewLendedBook);
		arrayLendedBook = new ArrayList<LendedBook>();
		createLendedBook();
		adapter = new LendedBookAdapter(Profile.this, R.layout.item_lendedbook, arrayLendedBook);
		listLendedBook.setAdapter(adapter);
		
		listLendedBook.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				Intent intent = new Intent(Profile.this, WebViewBook.class);
				
//				Bundle bundle = new Bundle();
//				bundle.putString("duongdan", arrayLendedBook.get(position).getDuongdanBook());
//				
//				intent.putExtras(bundle);
				
				startActivity(intent);
				//Toast.makeText(Profile.this,arrayLendedBook.get(position).getDuongdanBook() , Toast.LENGTH_SHORT).show();
			}
		});
	}
	
	private void createLendedBook() {
		LendedBook book1 = new LendedBook(
				BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher), 
				"Dieu Che tin hieu so", 
				"IT123", 
				"Trinh Van Loan", 
				"2004", 
				"20000", 
				"http://google.com.vn");
		arrayLendedBook.add(book1);
	}
}
